package com.zzw.testdemo01.block;

import com.zzw.testdemo01.container.CustomContainerOne;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.material.Material;
import net.minecraft.entity.MoverType;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.container.SimpleNamedContainerProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.Explosion;
import net.minecraft.world.IWorldReader;
import net.minecraft.world.World;
import net.minecraftforge.fml.network.NetworkHooks;

import java.util.Random;

public class BlockOne extends Block {
    public BlockOne() {
        super(Properties.of(Material.STONE).strength(1.5f).harvestLevel(2));
    }

    /**
     * 滑度0.98 = 冰
     * @return
     */
    @Override
    public float getFriction() {
        return 1.0f;
    }

    @Override
    public ActionResultType use(BlockState blockState, World world, BlockPos blockPos, PlayerEntity playerEntity, Hand hand, BlockRayTraceResult blockRayTraceResult) {
//        return super.use(blockState, world, blockPos, playerEntity, hand, blockRayTraceResult);
        // 创建并打开自定义GUI的逻辑

        // 给予玩家速度II效果，持续10秒
        playerEntity.addEffect(new EffectInstance(Effects.MOVEMENT_SPEED, 200, 1, false, false)); // 200ticks = 10秒, level 1 = II效果

        return ActionResultType.SUCCESS;
    }

    @Override
    public void attack(BlockState blockState, World world, BlockPos pos, PlayerEntity playerEntity) {
        super.attack(blockState, world, pos, playerEntity);

        // 爆出一个钻石
        if (!world.isClientSide) { // 确保只在服务器端执行
            ItemStack diamond = new ItemStack(Items.DIAMOND);
            Random rand = new Random();
            for (int i = 0; i < 1; ++i) { // 控制掉落数量，这里设置为1个
                double offsetX = rand.nextDouble() * 0.7D + 0.15D;
                double offsetY = rand.nextDouble() * 0.7D + 0.15D;
                double offsetZ = rand.nextDouble() * 0.7D + 0.15D;
                ItemEntity itemEntity = new ItemEntity(world,
                        pos.getX() + offsetX,
                        pos.getY() + offsetY,
                        pos.getZ() + offsetZ,
                        diamond);
                world.addFreshEntity(itemEntity);
            }
        }
    }





}
